﻿namespace SmartAssembly
{
    public sealed class ReportedStackFrame
    {
        private readonly string m_OriginalStackTraceLineOrNull;
        private readonly string m_MethodTypeNameOrNull;
        private readonly string m_MethodNameOrNull;
        private readonly string m_DocumentUrlOrNull;
        private readonly int? m_LineNumberOrNull;

        internal ReportedStackFrame(string originalStackTraceLineOrNull, string methodTypeNameOrNull, string methodNameOrNull, string documentUrlOrNull, int? lineNumberOrNull)
        {
            m_OriginalStackTraceLineOrNull = originalStackTraceLineOrNull;
            m_MethodTypeNameOrNull = methodTypeNameOrNull;
            m_MethodNameOrNull = methodNameOrNull;
            m_DocumentUrlOrNull = documentUrlOrNull;
            m_LineNumberOrNull = lineNumberOrNull;
        }

        public string GetBestStackTraceLine()
        {
            if (m_MethodTypeNameOrNull != null && m_MethodNameOrNull != null)
            {
                return string.Format("at {0}, {1}:{2}", m_MethodTypeNameOrNull, m_MethodNameOrNull, m_LineNumberOrNull);
            }

            return m_OriginalStackTraceLineOrNull;
        }

        internal string OriginalStackTraceLineOrNull
        {
            get { return m_OriginalStackTraceLineOrNull; }
        }

        public string DocumentUrlOrNull
        {
            get { return m_DocumentUrlOrNull; }
        }

        public int? LineNumberOrNull
        {
            get { return m_LineNumberOrNull; }
        }
    }
}